﻿using UnityEngine;
using System.Collections;

public class CharacterMovementScript : MonoBehaviour {

	public float maxSpeed = 10f;
	bool facingRight = true; // za sprite

	bool grounded = false;
	public Transform groundCheck;
	float groundRadius = 0.2f;
	public LayerMask whatIsGround;

	// Use this for initialization
	void Start () 
	{
	}

	void FixedUpdate()
	{
		grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);


		float move = Input.GetAxis ("Horizontal");
		rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);

	}
	// Update is called once per frame
	void Update () 
	{
		if (grounded && Input.GetAxis ("Jump") == 1f) {
			rigidbody2D.AddForce(new Vector2(0, 100f));
		}
	}
}
